home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / BlitzList / BlitzListFiles / KeyBoard_Interrupt.asc < prev    next >
Encoding:
Text File  |  1998-05-04  |  2.6 KB  |  110 lines

  1. ; This keyboard interrupt routine is adapted from
  2. ; one posted to the blitz list by Vivid Imagination
  3. ; Thanks for the original code!
  4. ;
  5. ; Simply put this in your code somewhere (preferably
  6. ; near the top :))
  7. ;
  8. ; The interrupt will set the following variables:
  9. ;
  10. ;  LastKey.b      - Contains the value of the last
  11. ;                   key event
  12. ;
  13. ;  LastKeyState.b - Set to one if the last key was
  14. ;                   detected pressed down and set
  15. ;                   to zero if the last key was up
  16. ;
  17. ;  KeyState.b()   - 128 byte array containing the
  18. ;                   status of all 128 keys. If the
  19. ;                   key is down the value in the
  20. ;                   array will be 1 otherwise 0
  21. ;
  22. ; Feel free to use this code in whatever you like!
  23. ;
  24. ;                                    -- Marcel Weber
  25.  
  26.  
  27. ;***************************;
  28. ;                           ;
  29. ; Keyboard interrupt begins ;
  30. ;                           ;
  31. ;***************************;
  32.  
  33. Dim KeyState.b(127)
  34. SetInt 3
  35.   MOVEQ   #0,d0
  36.   MOVE.b  $BFEC01,d0
  37.   NOT.b   d0
  38.   ROR.b   #1,d0
  39.   BTST    #7,d0
  40.   BNE     Key_Up
  41.   MOVEQ   #1,d1
  42.   BRA     Finish_Key
  43.   Key_Up:
  44.   BCLR    #7,d0
  45.   MOVEQ   #0,d1
  46.   Finish_Key:
  47.   PutReg  d0,LastKey.b
  48.   PutReg  d1,LastKeyState.b
  49.   GetReg  a0,&KeyState(LastKey)
  50.   MOVE.b  d1,(a0)
  51. End SetInt
  52.  
  53. ;***************************;
  54. ;                           ;
  55. ; End of Keyboard interrupt ;
  56. ;                           ;
  57. ;***************************;
  58.  
  59.  
  60.  
  61. ; The following code is a sample program used to test
  62. ; the above keyboard interrupt. It will open a window
  63. ; and display the most recent key press/release at
  64. ; the top of the window and below that there will be
  65. ; a list of all the keys currently held down.
  66. ;
  67. ; This program has two other uses as well :)
  68. ;
  69. ; 1) If you don't know the number for a particular key
  70. ;    on your keyboard then run this and hold down the
  71. ;    key to see what it is.
  72. ;
  73. ; 2) If you have an A1200 then you'll find keyboard
  74. ;    lockout a real pain. With this program you can
  75. ;    hold down various keys to see which ones lockout
  76. ;
  77. ; NOTE: Its limited to displaying 8 keys at once without
  78. ;       stuffing up. I couldn't press more than 8 on my
  79. ;       A1200 anyway ;)
  80.  
  81.  
  82. NoCli
  83. WBenchToFront_
  84. FindScreen 0
  85. Use Screen 0
  86. Window 0,0,0,270,90,$6,"Press ESC to Quit",0,0
  87. Format "000"
  88.  
  89. Repeat
  90.   WLocate 1,1
  91.   Print "Key: ",LastKey," is "
  92.   If LastKeyState = 1 Then NPrint "down" Else NPrint "up  "
  93.   NPrint ""
  94.  
  95.   KeysDown = 0
  96.   For a=0 To 127
  97.     If KeyState(a)=1 Then Print a," ": KeysDown+1
  98.   Next a
  99.  
  100.   For a=1 To (8-KeysDown)
  101.     Print "    "
  102.   Next a
  103.  
  104.   VWait
  105. Until KeyState(69)=1
  106.  
  107.  
  108. Free Window 0
  109. End
  110.